home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!txwang
- From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
- Newsgroups: comp.lang.c++
- Subject: Re: object creation from an abstract base class
- Date: Sun, 24 Mar 1996 16:47:51 GMT
- Message-ID: <199603240502.NAA06668@public1.guangzhou.gd.cn>
- X-NNTP-Posting-Host: txwang
- X-Newsreader: Forte Free Agent 1.0.82
- X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
-
- On 24 Mar 1996 01:16:48 GMT, Philippe Verdy
- <100105.3120@compuserve.com> wrote:
-
- | Wang TianXing <gztxwang@public1.guangzhou.gd.cn> s'crit :
- | > | >Michael Catello wrote:
- | > | >>
- | > | >> [code deleted]
- | > | >>
- | > | >> Obviously it is the CreateFoo() function that I am wondering about. In
- | > | >> the actual implementation I had multiple static "Create" functions for
- | > | >> the base class that would allow me to create a new object: one based
- | > | >> on an enumerated token (shown above), another an existing object, as
- | > | >> well as one based on the format of a datafile. My application never
- | > | >> references any of the derived classes directly, except in their
- | > | >> creation and definition.
- | > | >>
- | > | >> Is there another/better/more appropriate way to handle this type of
- | > | >> object creation? Thanks for your assistance,
- | > | >>
- | >
- | > So, the original poster should write code like this:
- | >
- | > CFoo *interface = new CBar;
- | >
- | > and remove the static function CFoo::CreateFoo(FooType);
- | >
- | No ! We need such a function in many C++ programs which have
- | to manage presistent collections of objects. However, such
- | applications do not use an enumeration but a registration
- | base class which is called by adding a static member to each
- | derived class, which will register themselves and obtain a
- | valid Id collected on a persistent stream. But on the final
- | result, managing such collections require that we have a
- | CFoo::CreateFoo(FooType) function in order to recreate the
- | collection of objects from a source which only enumerates
- | FooTypes. This is useful to create containers of graphic
- | objects with common attributes, and varying parameters
- | stored on a persistent stream, so that we can load and draw
- | the collection of objects without knowing anything on them.
- | Your code is legal Wang but you can generalize it to avoid
- | the switch() and the enumeration.
- | Philippe Verdy
-
- Well, Michael seems really interested in how to handle persistent
- objects elegantly. There's a good example in Borland C++: TStreamable
- and its related classes. It can write pointers into a stream.
- Michael may want to hack in the implementation to get some ideas.
-
- ---
- Wang TianXing
-
-
-